package com.link2room.soundwave.util;

import com.link2room.common.constant.AllPmsConstant;
import com.link2room.common.dto.threadlocal.BaseThreadLocal;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.util.StringUtil;
import com.link2room.common.util.SysoptionUtil;
import com.link2room.soundwave.exception.SoundwaveException;
import com.link2room.soundwave.facade.*;
import com.link2room.soundwave.facade.factory.AbstractPmsFactory;
import com.link2room.soundwave.facade.factory.SimplePmsFactory;


/**
 * Created by sss on 2017/5/19.
 */
public class HandlerUtil {
    public static IPmsRoomAvailHandlerFacadeService pmsRoomAvailHandler()throws Exception{
        String pmsType= SysoptionUtil.getSysOption(BaseThreadLocal.getLhotelGroupCode(), AllPmsConstant.CONFIG_CATEGORY,AllPmsConstant.CONFIG_ITEM.PMSTYPE);
        if(StringUtil.isBlank(pmsType)){
            throw new SoundwaveException(BaseSysExceptionEnum.PARAM_IS_NULL,"pmsType:"+pmsType);
        }else {
            AbstractPmsFactory abstractPmsFactory= SimplePmsFactory.create(pmsType);
            return abstractPmsFactory.createPmsRoomAvailHandler();
        }
    }

    public static IPmsRmtypeHandlerFacadeService pmsRmtypeHandler()throws Exception{
        String pmsType= SysoptionUtil.getSysOption(BaseThreadLocal.getLhotelGroupCode(), AllPmsConstant.CONFIG_CATEGORY,AllPmsConstant.CONFIG_ITEM.PMSTYPE);
        if(StringUtil.isBlank(pmsType)){
            throw new SoundwaveException(BaseSysExceptionEnum.PARAM_IS_NULL,"pmsType:"+pmsType);
        }else {
            AbstractPmsFactory abstractPmsFactory= SimplePmsFactory.create(pmsType);
            return abstractPmsFactory.createPmsRmtypeHandler();
        }
    }

    public static IPmsRateHandlerFacadeService pmsRateHandler()throws Exception{
        String pmsType= SysoptionUtil.getSysOption(BaseThreadLocal.getLhotelGroupCode(), AllPmsConstant.CONFIG_CATEGORY,AllPmsConstant.CONFIG_ITEM.PMSTYPE);
        if(StringUtil.isBlank(pmsType)){
            throw new SoundwaveException(BaseSysExceptionEnum.PARAM_IS_NULL,"pmsType:"+pmsType);
        }else {
            AbstractPmsFactory abstractPmsFactory= SimplePmsFactory.create(pmsType);
            return abstractPmsFactory.createPmsRateHandler();
        }
    }

    public static IPmsReservationHandlerFacadeService pmsReservationHandler()throws Exception{
        String pmsType= SysoptionUtil.getSysOption(BaseThreadLocal.getLhotelGroupCode(), AllPmsConstant.CONFIG_CATEGORY,AllPmsConstant.CONFIG_ITEM.PMSTYPE);
        if(StringUtil.isBlank(pmsType)){
            throw new SoundwaveException(BaseSysExceptionEnum.PARAM_IS_NULL,"pmsType:"+pmsType);
        }else {
            AbstractPmsFactory abstractPmsFactory= SimplePmsFactory.create(pmsType);
            return abstractPmsFactory.createPmsReservationHandler();
        }
    }

    public static IPmsMemberHandlerFacadeService pmsMemberHandler()throws Exception{
        String pmsType= SysoptionUtil.getSysOption(BaseThreadLocal.getLhotelGroupCode(), AllPmsConstant.CONFIG_CATEGORY,AllPmsConstant.CONFIG_ITEM.PMSTYPE);
        if(StringUtil.isBlank(pmsType)){
            throw new SoundwaveException(BaseSysExceptionEnum.PARAM_IS_NULL,"pmsType:"+pmsType);
        }else {
            AbstractPmsFactory abstractPmsFactory= SimplePmsFactory.create(pmsType);
            return abstractPmsFactory.createPmsMemberHandler();
        }
    }

    public static IPmsHotelHandlerFacadeService pmsHotelHandler()throws Exception{
        String pmsType= SysoptionUtil.getSysOption(BaseThreadLocal.getLhotelGroupCode(), AllPmsConstant.CONFIG_CATEGORY,AllPmsConstant.CONFIG_ITEM.PMSTYPE);
        if(StringUtil.isBlank(pmsType)){
            throw new SoundwaveException(BaseSysExceptionEnum.PARAM_IS_NULL,"pmsType:"+pmsType);
        }else {
            AbstractPmsFactory abstractPmsFactory= SimplePmsFactory.create(pmsType);
            return abstractPmsFactory.createPmsHotelHandler();
        }
    }
}
